package typejump.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

/**
 * This is the UIWidget that displays the user's command as they type it
 * @author g
 *
 */
public class CommandWidget implements UIWidget {
	
	private int avW = 0;
	private int avH = 0;
	
	private Rectangle bounds = new Rectangle(0, 0, 1, 1);
	private Font font = new Font("monospaced", Font.PLAIN, 16);
	private FontMetrics fm = null;
	
	private int fontHeight = 0;
	private int fontAscent = 0;
	
	private String command = "";
	
	public CommandWidget() {
		
	}
	
	public void setCommand(String command) {
		this.command = command;
	}

	@Override
	public void setAvailableSpace(int width, int height) {
		this.avW = width;
		this.avH = height;
		
		bounds.x = 0;
		bounds.width = width;
		bounds.y = height - bounds.height;
	}

	@Override
	public void paint(Graphics2D g) {
		g.setFont(font);
		if (fm == null) {
			fm = g.getFontMetrics();
			fontHeight = fm.getHeight();
			fontAscent = fm.getAscent();
			
			bounds.height = fontHeight + 4;
			bounds.y = this.avH - bounds.height;
		}
		
		g.setColor(Color.LIGHT_GRAY);
		g.fill(bounds);
		
		g.setColor(Color.BLACK);
		g.drawString(command, bounds.x + 2, bounds.y + 2 + fontAscent);
		
		g.draw(bounds);
	}

	@Override
	public Rectangle getBounds() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean keyEvent(KeyEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean mouseEvent(MouseEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

}
